package com.example.test;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.example.test.service.TraceServiceImpl;
import com.xdandroid.hellodaemon.DaemonEnv;
import com.xdandroid.hellodaemon.IntentWrapper;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_start:
                TraceServiceImpl.sShouldStopService = false;
                DaemonEnv.startServiceMayBind(TraceServiceImpl.class);
                break;
//            case R.id.btn_white:
//                IntentWrapper.whiteListMatters(this, "轨迹跟踪服务的持续运行");
//                break;
            case R.id.btn_stop:
                TraceServiceImpl.stopService();
                Observable.timer(3, TimeUnit.SECONDS)
                        .doOnSubscribe(disposable -> ToastUtils.showLong("3s后退出APP"))
                        .subscribe(time -> ActivityUtils.finishAllActivities());
                break;
        }
    }


    public void onBackPressed() {
        //防止华为机型未加入白名单时按返回键回到桌面再锁屏后几秒钟进程被杀
        //IntentWrapper.onBackPressed(this);
        //此处禁止返回退出APP，一定要点击退出按钮
    }
}
